package com.example.android.google.apis;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.android.apis.view.Map;
import com.example.android.logging.Logger;
import com.example.android.network.Client;

public class MainActivity extends Activity
{

	final int serverPort = 50001;
	final String defaultServerIp = "192.168.1.109";
public static String login;
	TextView textIp;
	TextView textLogin;
	TextView textPassword;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		Logger.CurrentContext = this;
		setContentView(R.layout.activity_main);

		final Button button = (Button) findViewById(R.id.go_button);
		textIp = (TextView) findViewById(R.id.ip_EditText);
		textLogin = (TextView) findViewById(R.id.login_editText);
		textPassword = (TextView) findViewById(R.id.password_editText);

		button.setOnClickListener(new OnButtonClick());
		textIp.setText(defaultServerIp);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	private class OnButtonClick implements View.OnClickListener
	{
		public void onClick(View v)
		{
			// --- setup
			String serverIpAddress = String.valueOf(textIp.getText());
			String login = String.valueOf(textLogin.getText());
			//String password = String.valueOf(textPassword.getText());

			Client.getInstance().connect(serverIpAddress, serverPort);
			//Updater.getInstance().login(login);
			MainActivity.login=login;//cuz sockets suck
			// ---

			// start activity
			Intent intent = new Intent(MainActivity.this,
					Map.class);
			MainActivity.this.startActivity(intent);
		}
	}
}
